package cn.snorlaxzjt.LBSserver.common;

import cn.snorlaxzjt.LBSserver.po.entity.User;
import cn.snorlaxzjt.LBSserver.po.page.FriendPage;
import cn.snorlaxzjt.LBSserver.po.page.MomentPage;
import cn.snorlaxzjt.LBSserver.po.entity.Moment;

import java.util.List;
import java.util.stream.Collectors;

public class Converter {

    public static MomentPage toMomentPage(Moment moment)
    {
        MomentPage momentPage = new MomentPage();
        momentPage.setId(moment.getId());
        momentPage.setContent(moment.getContent());
        momentPage.setAvatar(moment.getAvatar());
        momentPage.setAddress(moment.getAddress());
        momentPage.setLandmark(moment.getLandmark());
        momentPage.setUserId(momentPage.getUserId());
        momentPage.setCreateTime(moment.getCreateTime());
        momentPage.setLatitude(moment.getLatitude());
        momentPage.setLongitude(moment.getLongitude());
        momentPage.setUserId(moment.getUserId());
        momentPage.setUsername(moment.getUsername());
        momentPage.setImageUrl(moment.getImageUrl());
        momentPage.setAvatar(moment.getAvatar());
        return momentPage;
    }

    public static FriendPage toFriendPage(List<User> item1, List<User> item2, List<User> item3){
        List<Integer> friendIdList = item3.stream().map(User::getId).collect(Collectors.toList());
        List<FriendPage.FriendPageInfo> list1 =  item1.stream().map(obj -> toFriendPageInfo(obj,1,friendIdList)).collect(Collectors.toList());
        List<FriendPage.FriendPageInfo> list2 =  item2.stream().map(obj -> toFriendPageInfo(obj,1,friendIdList)).collect(Collectors.toList());
        List<FriendPage.FriendPageInfo> list3 =  item3.stream().map(obj -> toFriendPageInfo(obj,1,friendIdList)).collect(Collectors.toList());
        return new FriendPage(list1,list2,list3);
    }

    public static FriendPage.FriendPageInfo toFriendPageInfo(User u,int stu,List<Integer> list){
        FriendPage.FriendPageInfo res = new FriendPage.FriendPageInfo();
        res.setAvatar(u.getAvatar());
        res.setEmail(u.getEmail());
        res.setId(u.getId());
        res.setUsername(u.getUsername());
        if(list.contains(u.getId())){
            res.setStatus("已互关");
        }else{
            if(stu == 1)
                res.setStatus("已关注");
            if(stu == 2)
                res.setStatus("回关");
        }
        return res;
    }

}
